package com.wimcorp.magic.abilities.trigger;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.wimcorp.magic.abilities.Ability;
import com.wimcorp.magic.cards.PlayingCard;

@Entity
@Table(name = "abilitytrigger", schema = "abilities")
public abstract class AbilityTrigger {
	
	private static long identifierCounter = 1;
	
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	private Long id;
	
	@Transient
	private long identifier;

	@OneToOne(fetch = FetchType.EAGER)
	private Ability ability;

	protected AbilityTrigger() {
	}

	public AbilityTrigger(Ability ability) {
		setAbility(ability);
	}

	public AbilityTrigger(AbilityTrigger abilityTrigger) {
		identifier = identifierCounter++;
		this.ability = abilityTrigger.getAbility();
	}

	public abstract void register();

	public abstract void unRegister();

	public Ability getAbility() {
		return ability;
	}

	public void setAbility(Ability ability) {
		this.ability = ability;
		if (ability.getTrigger() == null) {
			ability.setTrigger(this);
		}

	}

	public abstract AbilityTrigger clone();
		

}